package com.ccbooks.listener;

import com.ccbooks.bo.FileBo;
import com.ccbooks.util.ContentDisp;
import com.ccbooks.util.ContentUtilContentSize;
import com.ccbooks.util.CursorController;
import com.ccbooks.util.MeasureText;
import com.ccbooks.util.StringConfig;
import com.ccbooks.util.TextSizeUtil;
import com.ccbooks.util.PDB.ContentDispPDB;
import com.ccbooks.util.PDB.ContentUtilContentSizePDB;
import com.ccbooks.view.BookContentView;
import com.ccbooks.view.R;

import android.graphics.Typeface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.TextView;

public class BtnFontEnterButtonClick implements OnClickListener{

	private BookContentView bcv;
	private TextView tvMainContent;
	private TextView tvMainContentLeft;
	private TextView tvMainContentRight;
	private Button btnFontEnterButtonA2; //字体变大按钮；
	private Button btnFontEnterColorBlack; //白背景按钮；
	private Button btnFontEnterColorBrown; //棕色背景按钮；
	private ContentUtilContentSize cucs;
	private ContentUtilContentSizePDB cucsPDB;
	private String content;
	private int lineCount;


	private int fontSize;

	public BtnFontEnterButtonClick(BookContentView bcv,TextView tvMainContent,
			TextView tvMainContentLeft, TextView tvMainContentRight,
			Button btnFontEnterButtonA2, Button btnFontEnterColorBlack,
			Button btnFontEnterColorBrown) {
		super();
		this.bcv = bcv;
		this.tvMainContent = tvMainContent;
		this.tvMainContentLeft = tvMainContentLeft;
		this.tvMainContentRight = tvMainContentRight;
		this.btnFontEnterButtonA2 = btnFontEnterButtonA2;
		this.btnFontEnterColorBlack = btnFontEnterColorBlack;
		this.btnFontEnterColorBrown = btnFontEnterColorBrown;
	}
	
	
	//点击字体变小按钮；
	

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			if( bcv.portraint == 1 ) {
				tvMainContent.setText( null );
			} else if ( bcv.portraint == 2) {
				tvMainContentLeft.setText(null);
				tvMainContentRight.setText(null);
			}
			bcv.dg.show();
			if(FileBo.BOOKTYPE_TXT.equals(bcv.book.booktype)){
					if (bcv.portraint == 1) {
						if(bcv.showFontEnterButtona1==1){
							 String familyName = "MONOSPACE";
						        Typeface font = Typeface.create(familyName,Typeface.ITALIC);
						        
						        tvMainContent.setTypeface(font);
						        float textSize =  tvMainContent.getTextSize()-4.0f;
						        if(textSize <=10.0f){
						        	textSize = 10.0f;
						        }
						        fontSize = (int)textSize;
						        tvMainContent.setTextSize(textSize); 
							
							((Button)v).setBackgroundResource(R.drawable.content_btn_font_enter_a_selected);
							btnFontEnterButtonA2.setBackgroundResource(R.drawable.content_btn_font_enter_b);
		
							btnFontEnterColorBrown.setBackgroundResource(R.drawable.content_btn_color_brown);
							btnFontEnterColorBlack.setBackgroundResource(R.drawable.content_btn_color_black);
		
							bcv.showFontEnterButtonA2=1;
							bcv.showFontEnterButtona1=2;
							TextSizeUtil.fontSize = fontSize;
							lineCount = TextSizeUtil.getLineCount(fontSize, bcv.portraint);
							bcv.lineCount = lineCount;
							cucs = new ContentUtilContentSize(bcv, bcv.book.bookpath, "宋体", StringConfig.VWIDE, "GBK", bcv.portraint); 
							
							Thread th = new Thread(cucs);
							th.start();
							
							bcv.cd = new ContentDisp(bcv, bcv.book.bookpath, "宋体",StringConfig.VWIDE,"GBK", bcv.portraint,cucs.engine, bcv.portraint);
							
							bcv.cc = new CursorController(cucs.engine,bcv. cd, bcv.cur,  bcv,bcv.cuf);
							bcv.cd.setLine(0, lineCount);
							
							bcv.cd.what = 1;
							
							
							Thread ths= new Thread(bcv.cd);
							ths.start();
							
						}else{
							((Button)v).setBackgroundResource(R.drawable.content_btn_font_enter_a);
							
							bcv.showFontEnterButtona1=1;
						}
					} else if (bcv.portraint == 2) {
						
						if(bcv.showFontEnterButtona1==1){
							 String familyName = "MONOSPACE";
						        Typeface font = Typeface.create(familyName,Typeface.ITALIC);
						        
						        tvMainContentLeft.setTypeface(font);
						        tvMainContentRight.setTypeface(font);
						        float textSize =  tvMainContentLeft.getTextSize()-4.0f;
						        if(textSize <=10.0f){
						        	textSize = 10.0f;
						        }
						        fontSize = (int)textSize;
						        tvMainContentLeft.setTextSize(textSize); 
						        tvMainContentRight.setTextSize(textSize); 
							
							((Button)v).setBackgroundResource(R.drawable.content_btn_font_enter_a_selected);
							btnFontEnterButtonA2.setBackgroundResource(R.drawable.content_btn_font_enter_b);
		
							btnFontEnterColorBrown.setBackgroundResource(R.drawable.content_btn_color_brown);
							btnFontEnterColorBlack.setBackgroundResource(R.drawable.content_btn_color_black);
		
							bcv.showFontEnterButtonA2=1;
							bcv.showFontEnterButtona1=2;
							TextSizeUtil.fontSize = fontSize;
							
							lineCount = TextSizeUtil.getLineCount(fontSize, bcv.portraint);
							bcv.lineCount = lineCount;
							cucs = new ContentUtilContentSize(bcv, bcv.book.bookpath, "宋体",StringConfig.HWIDE, "GBK", bcv.portraint); 
							
							Thread th = new Thread(cucs);
							th.start();
							
							bcv.cd = new ContentDisp(bcv, bcv.book.bookpath, "宋体",StringConfig.HWIDE,"GBK", bcv.portraint,cucs.engine, bcv.portraint);
							
							bcv.cc = new CursorController(cucs.engine,bcv. cd, bcv.cur,  bcv,bcv.cuf);
							bcv.cd.setLine(0, lineCount);
							
							bcv.cd.what = 2;
							
							
							Thread ths= new Thread(bcv.cd);
							ths.start();
						}else{
							((Button)v).setBackgroundResource(R.drawable.content_btn_font_enter_a);
							
							bcv.showFontEnterButtona1=1;
							bcv.showFontEnterButtonA2=1;
						}
					}
			}else if(FileBo.BOOKTYPE_PDB.equals(bcv.book.booktype)){
				if (bcv.portraint == 1) {
					if(bcv.showFontEnterButtona1==1){
						 String familyName = "MONOSPACE";
					        Typeface font = Typeface.create(familyName,Typeface.ITALIC);
					        
					        tvMainContent.setTypeface(font);
					        float textSize =  tvMainContent.getTextSize()-4.0f;
					        if(textSize <=10.0f){
					        	textSize = 10.0f;
					        }
					        fontSize = (int)textSize;
					        tvMainContent.setTextSize(textSize); 
						
						((Button)v).setBackgroundResource(R.drawable.content_btn_font_enter_a_selected);
						btnFontEnterButtonA2.setBackgroundResource(R.drawable.content_btn_font_enter_b);
	
						btnFontEnterColorBrown.setBackgroundResource(R.drawable.content_btn_color_brown);
						btnFontEnterColorBlack.setBackgroundResource(R.drawable.content_btn_color_black);
	
						bcv.showFontEnterButtonA2=1;
						bcv.showFontEnterButtona1=2;
						TextSizeUtil.fontSize = fontSize;
						lineCount = TextSizeUtil.getLineCount(fontSize, bcv.portraint);
						bcv.lineCount = lineCount;
						cucsPDB = new ContentUtilContentSizePDB(bcv, bcv.book.bookpath, "宋体", StringConfig.VWIDE, "GBK", bcv.portraint); 
						
						Thread th = new Thread(cucsPDB);
						th.start();
						
						bcv.cdPDB = new ContentDispPDB(bcv, bcv.book.bookpath, "宋体",StringConfig.VWIDE,"GBK", bcv.portraint,cucsPDB.engine, bcv.portraint);
						
						bcv.cc = new CursorController(cucsPDB.engine, bcv.cuPDB,  bcv.cdPDB, bcv, bcv.cufPDB);
						bcv.cdPDB.setLine(0, lineCount);
						
						bcv.cdPDB.what = 4;
						
						
						Thread ths= new Thread(bcv.cdPDB);
						ths.start();
						
					}else{
						((Button)v).setBackgroundResource(R.drawable.content_btn_font_enter_a);
						
						bcv.showFontEnterButtona1=1;
					}
				} else if (bcv.portraint == 2) {
					
					if(bcv.showFontEnterButtona1==1){
						 String familyName = "MONOSPACE";
					        Typeface font = Typeface.create(familyName,Typeface.ITALIC);
					        
					        tvMainContentLeft.setTypeface(font);
					        tvMainContentRight.setTypeface(font);
					        float textSize =  tvMainContentLeft.getTextSize()-4.0f;
					        if(textSize <=10.0f){
					        	textSize = 10.0f;
					        }
					        fontSize = (int)textSize;
					        tvMainContentLeft.setTextSize(textSize); 
					        tvMainContentRight.setTextSize(textSize); 
						
						((Button)v).setBackgroundResource(R.drawable.content_btn_font_enter_a_selected);
						btnFontEnterButtonA2.setBackgroundResource(R.drawable.content_btn_font_enter_b);
	
						btnFontEnterColorBrown.setBackgroundResource(R.drawable.content_btn_color_brown);
						btnFontEnterColorBlack.setBackgroundResource(R.drawable.content_btn_color_black);
	
						bcv.showFontEnterButtonA2=1;
						bcv.showFontEnterButtona1=2;
						TextSizeUtil.fontSize = fontSize;
						
						lineCount = TextSizeUtil.getLineCount(fontSize, bcv.portraint);
						bcv.lineCount = lineCount;
						cucsPDB = new ContentUtilContentSizePDB(bcv, bcv.book.bookpath, "宋体",StringConfig.HWIDE, "GBK", bcv.portraint); 
						
						Thread th = new Thread(cucsPDB);
						th.start();
						
						bcv.cdPDB = new ContentDispPDB(bcv, bcv.book.bookpath, "宋体",StringConfig.HWIDE,"GBK", bcv.portraint,cucsPDB.engine, bcv.portraint);
						
						bcv.cc = new CursorController(cucsPDB.engine,bcv.cuPDB,bcv. cdPDB,   bcv,bcv.cufPDB);
						bcv.cdPDB.setLine(0, lineCount);
						
						bcv.cdPDB.what = 7;
						
						
						Thread ths= new Thread(bcv.cdPDB);
						ths.start();
					}else{
						((Button)v).setBackgroundResource(R.drawable.content_btn_font_enter_a);
						
						bcv.showFontEnterButtona1=1;
						bcv.showFontEnterButtonA2=1;
					}
				}
			}else if(FileBo.BOOKTYPE_CHM.equals(bcv.book.booktype)){
				
			}else if(FileBo.BOOKTYPE_HTML.equals(bcv.book.booktype)){
				
			}else if(FileBo.BOOKTYPE_PDF.equals(bcv.book.booktype)){
				
			}
		}
		/**改变字体大小*/
		public void contentSize(int fontSize){
			TextSizeUtil.fontSize=fontSize;
			lineCount = TextSizeUtil.getLineCount(fontSize, bcv.portraint);
			
			cucs = new ContentUtilContentSize(bcv, bcv.book.bookpath, "宋体",  StringConfig.VWIDE, "GBK", bcv.portraint); 
			
			Thread th = new Thread(cucs);
			th.start();
			if (bcv.portraint == 1){
				bcv.cd = new ContentDisp(bcv, bcv.book.bookpath, "宋体",StringConfig.VWIDE,"GBK", bcv.portraint,cucs.engine, bcv.portraint);
			} else if (bcv.portraint ==2 ){
				bcv.cd = new ContentDisp(bcv, bcv.book.bookpath, "宋体",StringConfig.HWIDE,"GBK", bcv.portraint,cucs.engine, bcv.portraint);
			}
			bcv.cc = new CursorController(cucs.engine,bcv. cd, bcv.cur,  bcv,bcv.cuf);
			bcv.cd.setLine(0, lineCount);
			if (bcv.portraint == 2){
				bcv.cd.what = 1;
			}else if (bcv.portraint == 2){
				bcv.cd.what = 2;
			}
			
			Thread ths= new Thread(bcv.cd);
			ths.start();
			
			
		}
}
